<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddSomeColumnsToProducts extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('products', function (Blueprint $table) {
            $table->unsignedBigInteger('brand_id');
            $table->foreign('brand_id')->references('id')->on('brands')->onDelete('cascade');
            $table->unsignedBigInteger('supplier_id');
            $table->foreign('supplier_id')->references('id')->on('suppliers')->onDelete('cascade');
            $table->unsignedInteger('base_sale')->default(0)->comment('基础销量');
            $table->unsignedInteger('base_recommend')->default(0)->comment('基础推荐');
            $table->unsignedInteger('base_share')->default(0)->comment('基础分享');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('products', function (Blueprint $table) {
            $table->dropForeign('brand_id');
            $table->dropForeign('supplier_id');
            $table->dropColumn('brand_id');
            $table->dropColumn('supplier_id');
            $table->dropColumn('production_date');
            $table->dropColumn('base_sale');
            $table->dropColumn('base_recommend');
            $table->dropColumn('base_share');
        });
    }
}
